Repository navigation
Derived parameters for dynamics - #21
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lets a dynamics model declare values computed from its other parameters, the counterpart of TVB's
update_derived_parametersand of couplingprecompute. Includes the TVBReducedSetFitzHughNagumoport that motivates it, and a coupling channel fix it surfaced.How it works
paramsthatdynamics()receives.Network/HeterogeneousNetwork, native and Diffrax,observe=probe). Gradients flow to the primary parameters.Design decisions to discuss
config.dynamicsholds only primary parameters, so nothing can go stale. To make a quantity free, promote it toDEFAULT_PARAMSin a subclass. Fitting a function of one parameter is a reparameterization (TransformedParameter).DERIVED_PARAMSuses ordinary inheritance: omit to inherit, define to replace (()removes all). This differs fromSTATE_NAMESetc. on purpose, so promotion works.Misuse (wrong declaration, overlap with
DEFAULT_PARAMS, missing hook, wrong hook output,Model(rate=...),config.dynamics.rate = ...) raises errors that name the model, field and config location.Performance
XLA already hoists invariant parameter math out of the forward scan, but not out of the backward pass. Cheap scalar derivations can stay inline; expensive (e.g. matrix-valued) derivations under gradients benefit substantially.
Example model:
ReducedSetFitzHughNagumoPort of TVB's model, whose mode coefficients (
Aik,Bik,Cik,e_i, ...) are integrals over the input distribution N(mu,sigma). They are now derived parameters, somuandsigmacan be swept or fitted by gradient descent, which TVB cannot do. Derived arrays,dfunand network trajectories (instant and delayed) match TVB. Its network input is the coupled sum of the three xi modes, provided by the newSumLinearCoupling.Coupling channels
The port surfaced two gaps in the coupling contract:
LinearCouplingcould not transport several states.Networknever compared a coupling's channels with the model'sCOUPLING_INPUTS. JAX clamps out-of-range rows silently, so e.g.MontbrioPazoRoxinwithLinearCoupling(source="r")received the r coupling as its V coupling.Changes:
Linear,Difference,Sigmoid,Tanh,Kuramoto, delayed variants) produce one channel per source state (N_OUTPUT_STATES = PER_SOURCE). Single-source use is unchanged.SumLinearCoupling/DelayedSumLinearCouplingsum the source states before transport (one channel, one transport).Networkchecks channel counts againstCOUPLING_INPUTS. Heterogeneous routes check against the readout width, atprepare()for callable readouts.pre()combines states: they must now declareN_OUTPUT_STATES, and the error says so.MontbrioPazoRoxinandEpileptorwith both coupled states and routesWilsonCowan's network term todelayed(itsinstantinput is TVB's local coupling). The tests' tinyGhad hidden the old wiring.Changes
dynamics/base.py:DERIVED_PARAMS,derived_params(),resolve_params(), validationsolve.py: resolve once per solve on all dispatch paths; route channel checkutils/printer.py: show derived names and hook sourcedynamics/tvb/reduced_set.py:ReducedSetFitzHughNagumocoupling/: per-source channels,SumLinearCoupling, clearerpre()channel errors;core/network.py,core/heterogeneous.py: channel checksdynamics.qmd, "Output Channels" incoupling.qmd, skill referencestest_derived_params.py,test_reduced_set.py,test_coupling_channels.py, TVB comparison entries